<?php
	require_once $ubi['SERVER']['SERVER_ROOT'] . '/admin/dao/daoQuestionProvider.php';
	require_once $ubi['SERVER']['SERVER_ROOT'] . '/admin/model/question.php';
	
	class QuestionProviderBus {
		private $_questionProviderDao;
		
		public function __construct() {
			$this->_questionProviderDao = new QuestionProviderDao();				
		}
		
		public function addQuestionProvider($xmlString, $catID) {
			$this->_questionProviderDao->deleteQuestionProvider($catID);
			$xml = simplexml_load_string($xmlString);
			
			foreach ($xml->Question as $question) {
				$question_provider = new QuestionModel();
				
				$nodeAnswers = $question->xpath('answers');
				
				$question_provider->setAnswers($nodeAnswers[0]->asXML());
				$question_provider->setCategoryID($catID);
				$attr = $question->attributes();
				$question_provider->setQuestion($attr['content']);
				
				$this->_questionProviderDao->addQuestionProvider($question_provider);
			} 
			
			return 1;
		}
	}
?>